package com.itheima.controller;

import com.itheima.R;
import com.itheima.pojo.SmsHomeBrand;
import com.itheima.service.SmsHomeBrandService;
import com.itheima.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author pk
 * @date 2022/10/13/15:51
 */
@RestController
@RequestMapping("home/brand")
public class SmsHomeBrandController {

    @Autowired
    private SmsHomeBrandService brandService;

    /**
     * 添加首页推荐品牌
     * @param brand
     * @return
     */
    @PostMapping("/create")
    public R createBrand(@RequestBody SmsHomeBrand brand){

        brandService.createBrand(brand);
        return R.success("添加品牌功能执行");
    }

    /**
     * 分页查询推荐品牌
     * @param brandName
     * @param pageNum
     * @param pageSize
     * @param recommendStatus
     * @return
     */
    @GetMapping("/list")
    public R findBrands(String brandName,@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                        @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize,Integer recommendStatus){

        PageResult result=brandService.findBrands(brandName,pageNum,pageSize,recommendStatus);
        return R.success(result);
    }

    /**
     * 修改推荐品牌排序
     * @param id
     * @param sort
     * @return
     */
    @PostMapping("/update/sort/{id}")
    public R updateSortByid(@PathVariable Long id,Integer sort){
        brandService.updateSortByid(id,sort);
        return R.success("修改品牌排序功能执行");
    }


    /**
     * 批量删除品牌
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public R deleteBrands(Integer[] ids){

        brandService.deleteBrands(ids);
        return R.success("批量删除品牌功能执行");
    }


    /**
     * 批量修改品牌状态
     * @param ids
     * @param recommendStatus
     * @return
     */
    @PostMapping("/update/recommendStatus")
    public R updateRecommendStatus(Integer[] ids,Integer recommendStatus){
        brandService.updateRecommendStatus(ids,recommendStatus);
        return R.success("批量修改品牌状态功能执行");
    }
}
